using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ResultEntity
    {
        /// <summary>
        /// 状态 1 表示成功，0表示初始状态，-1 表示错误或失败
        /// </summary>
        public int State { get; set; }
        /// <summary>
        /// 说明
        /// </summary>
        public string Message { get; set; }


        /// <summary>
        /// 默认状态
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity Default(string message = null)
        {
            ResultEntity result = new ResultEntity();
            result.State = 0;
            result.Message = message;
            return result;
        }

        /// <summary>
        /// 成功状态
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity Success(string message = null)
        {
            ResultEntity result = new ResultEntity();
            result.State = 1;
            result.Message = message;
            return result;
        }

        /// <summary>
        /// 失败状态
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity Error(string message = null)
        {
            ResultEntity result = new ResultEntity();
            result.State = -1;
            result.Message = message;
            return result;
        }

    }

    public class ResultEntity<T> : ResultEntity
        where T : class
    {
        public T Entity;

        /// <summary>
        /// 默认状态
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity<T> Default(T entity, string message)
        {
            var result = new ResultEntity<T>()
            {
                Message = message,
                State = 0,
                Entity = entity
            };
            return result;
        }

        /// <summary>
        /// 成功状态
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity<T> Success(T entity, string message)
        {
            var result = new ResultEntity<T>
            {
                State = 1,
                Message = message,
                Entity = entity
            };

            return result;
        }

        /// <summary>
        /// 错误状态
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultEntity<T> Error(T entity, string message)
        {
            var result = new ResultEntity<T>
            {
                State = -1,
                Message = message,
                Entity = entity
            };
            return result;
        }

    }
}


